/**
 * @author 蒙伟明
 * @data 2020年6月11日
 */
package com.ysxm.service.adminservice.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.ysxm.dao.adminmapper.AUserDao;

import com.ysxm.entity.User;
import com.ysxm.service.adminservice.AUserService;
import com.ysxm.util.CustomException;

/**
 * @author mwm
 *
 */
@Service
@Transactional
public class AUserServiceImpl implements AUserService {
	@Autowired
	private AUserDao aUserDao;
	@SuppressWarnings("unused")
	private List<User> auList;

	/* 添加用户
	 */
	public boolean addAUser(User user) {
		Boolean b=aUserDao.addAUser(user);
		return b;
	}

	/* 修改用户信息
	 */
	public boolean updateAUser(User user) {
		Boolean b=aUserDao.updateAUser(user);
		return b;
	}

	/* 删除用户
	 */
	public boolean deleteAUser(Integer uid) {
		try {
			return aUserDao.deleteAUser(uid);
		} catch (Exception e) {
			e.printStackTrace();
			throw new CustomException("删除失败");
		}

		
	}

	/* (non-Javadoc)
	 * @see com.ysxm.service.adminservice.AUserService#findAUserById(java.lang.Integer)
	 */
	public User findAUserById(Integer uid) {
		
		return aUserDao.findAUserById(uid);
	}

	/* (non-Javadoc)
	 * @see com.ysxm.service.adminservice.AUserService#findAllAUser(int, int)
	 */
	public List<User> findAllAUser(int pageNum, int pageSize) {
		// pageNum代表页码值，pageSize代表每页条数
				PageHelper.startPage(pageNum, pageSize);
				List<User> aulist = aUserDao.findAllAUser(pageNum, pageSize);
				return aulist;
	}

	/* (non-Javadoc)
	 * @see com.ysxm.service.adminservice.AUserService#findAllAUser()
	 */
	public List<User> findAllAUser() {
		try {
			List<User> allauser=aUserDao.findAllAUser();
			return allauser;
		} catch (Exception e) {
			e.printStackTrace();
			throw new CustomException("显示失败");
		}
	
	}

	/* (non-Javadoc)
	 * @see com.ysxm.service.adminservice.AUserService#selectAUserByName(java.lang.String)
	 */
	public Boolean selectAUserByName(String username) {

		boolean b;
		if (aUserDao.selectAUserByName(username) == null) {
			b = true;
		} else {
			b = false;
		}
		return b;
	}

	/* (non-Javadoc)
	 * @see com.ysxm.service.adminservice.AUserService#findAUserListBy(com.ysxm.entity.User)
	 */
	//管理員以用戶名模糊查詢
			public List<User> findAUserListByName(String username) {
				if (username == null || username.equals("")) {
					throw new CustomException("请输入内容");
				}
				try {
					List<User> auList=aUserDao.findAUserListByName(username);
					return auList;
					
				} catch (Exception e) {
					e.printStackTrace();
					throw new CustomException("查询无此人");
				}
	}
}
